﻿var currentPage = 1; // 当前页
var pageSize = 6; // 每页显示多少条
var pageall = 0; // 总页数
var total = 0; // 总记录数

$(document).ready(function() {
    focus();
    var id = LexunJS.GetQueryString("id"); // 楼盘ID
    var typeid = LexunJS.GetQueryString("typeid"); // 0 必须打跟进 1不需打跟进
    if (typeid == 0)
        document.getElementById("divPhone").style.display = "block";

    if (id > 0) {
        ShowFollow(1);
    }
});


function ClearText(obj) {
    obj.value = "";
}

function reload() {///判断Session 是否失效
    $.ajax({
        type: 'POST',
        url: '../Handler/HandlerHousing.ashx',
        data: 'act=GetInfo',
        timeout: '10000',
        error: function() {
            alert("系统繁忙，请稍后再试！");
        },
        success: function(json) {
        if (json <= 0) {
               window.returnValue = 1;
               window.close();
             }
        }
    });
}
//setInterval("reload()", 10000);

//查询跟进
function ShowFollow(currentPage) {
    var id = LexunJS.GetQueryString("id");

    $.ajax({
        type: 'POST',
        url: '../Handler/HandlerHousing.ashx',
        data: 'act=SelectFollow&id=' + id + '&page=' + currentPage + '&pagesize=' + pageSize,
        timeout: '10000',
        error: function() {
            alert("系统繁忙，请稍后再试！");
        },
        success: function(json) {
            ShowFlowCallBack(json);
        }
    });
}

function ShowFlowCallBack(response) {
    var json = eval("(" + response + ")");
    var record = json.record;

    var page = json.page;

    currentPage = page.currentpage;
    pageall = parseInt(page.pageall);
    total = page.total;

    if (record == null || record.length == 0) return;
    $("#divList").html(""); // 显示列表
    var arr = [];
    arr.push("<table id='table1' width='98%' border='0' cellpadding='0' cellspacing='1' bgcolor='#a8c7ce'>");
    arr.push("<tr>");
    arr.push("<td height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("跟进时间");
    arr.push("</td>");
    arr.push("<td height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("部门");
    arr.push("</td>");
    arr.push("<td height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("跟进人");
    arr.push("</td>");
    arr.push("<td height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("跟进内容");
    arr.push("</td>");
    arr.push("</tr>");
    for (var i = 0; i < record.length; i++) {
        if (i % 2 == 0)
            arr.push("<tr id='tr_" + record[i].id + "' bgcolor='#FFFFFF' style='cursor: pointer;' >");
        else
            arr.push("<tr id='tr_" + record[i].id + "' bgcolor='#EEEDED' style='cursor: pointer;' >");
     
        arr.push("<td height='25' class='STYLE10'>");
        arr.push("" + record[i].fdate + "</td>");
        arr.push("<td height='25'  class='STYLE10'>");
        arr.push("" + record[i].fdept + "</td>");
        arr.push("<td height='25'  class='STYLE10'>");
        arr.push("" + record[i].fuser + "</td>");
        arr.push("<td height='25'  class='STYLE7'>");
        arr.push("<font color='blue'>" + record[i].followtype + "</font>:" + record[i].fcontent + "");
        if (record[i].fimportant != "") {
            arr.push("&nbsp;&nbsp;重要备注：<font color='red'>" + record[i].fimportant + "</font>");
        }
        arr.push("</td>");
        
        arr.push("</tr>");
    }
    arr.push("</table>");
    
    $("#divList").html(arr.join('')); // 显示列表
    $("#divPage").html(""); // 清空
    if (pageall > 1) {        
        pageSize = 50;
        $("#divPage").html("<a href=\"javascript:ShowFollow(1)\">更多...</a>");
    } else {
        pageSize = 6;
        $("#divPage").html("<a href=\"javascript:ShowFollow(1)\">刷新</a>");
    }
}

function Show() {
    var cbo1 = document.getElementById("cbo1");
    if (cbo1.checked == true) {
        document.getElementById("div2").style.display = "";
        document.getElementById("cboname").value = "0";

    } else {
        document.getElementById("div2").style.display = "none";
        document.getElementById("cboname").value = "1";

    }
    var cbo2 = document.getElementById("cbo2");
    if (cbo2.checked == true) {
        document.getElementById("div1").style.display = "";
        document.getElementById("isalert").value = "0";
    } else {
        document.getElementById("div1").style.display = "none";
        document.getElementById("isalert").value = "1";

    }
}

//提交
function submitOk() {
    var id = LexunJS.GetQueryString("id");
    document.getElementById("housingId").value = id;

    var fcontent = document.getElementById("fContent").value;
    if (LexunJS.Trim(fcontent) == "") {
        alert("请输入跟进内容！");
        return false;
    }

//    var cbo1 = document.getElementById("cbo1");
//    var cbo2 = document.getElementById("cbo2");
//    if (cbo1.checked) {
//        var AlertContent = document.getElementById("AlertContent").value;
//        if (LexunJS.Trim(AlertContent) == "") {
//            alert("请输入提醒内容！");
//            return false;
//        }
//    }
//    if (!cbo2.checked && !cbo1.checked) {
//        if (LexunJS.Trim(fcontent) == "") {
//            alert("请输入跟进内容！");
//            return false;
//        }
//    }

//            var fcontent = document.getElementById("fContent").value;
//            if (fcontent != "") {
//                var fprice = document.getElementById("fprice").value;
//                if (fprice == "") {
//                    alert("请输入最新总价！");
//                    return false;
//                } 
//            }

    //提交信息
    document.forms[0].submit();

    $("#btnOK").attr("disabled", "true");
    $("#btnOK").attr("value", "正在提交...");
}

function checkNum(str) {
    var num = str.value;

    var reg = /^\d+$/;
    if (!num.match(reg)) {
        alert("请输入数字！");
        str.value = "";
        str.focus();
    }
    return false;
}
